package net.hn.hnms.biz.safety.trinity.company.service;

import lombok.RequiredArgsConstructor;
import net.hn.hnms.biz.api.safety.trinity.model.TreeViolationsManagementVo;
import net.hn.hnms.biz.safety.trinity.dao.WorkSafetyViolationDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import java.util.List;
import java.util.Map;

/**
 * @author 智呈物联 nzw
 * @date 2023/1/5
 */

@Service
@RequiredArgsConstructor
public class WorkSafetyViolationCompanyService {

    private final JdbcTemplate locationJdbcTemplate;

    WorkSafetyViolationDao workSafetyViolationDao;

    EntityManager entityManager;

    @Autowired
    public void setWorkSafetyViolationDao(WorkSafetyViolationDao workSafetyViolationDao) {
        this.workSafetyViolationDao = workSafetyViolationDao;
    }

    public TreeViolationsManagementVo threeViolations(){
        TreeViolationsManagementVo treeViolationsManagementVo = new TreeViolationsManagementVo();
        //三违总数
        treeViolationsManagementVo.setViolationCount(workSafetyViolationDao.countAll());

        List<Map<String,Object>> list = workSafetyViolationDao.threeViolations();
        for(Map map:list){
            if (map.get("violation_level")!=null){
                String violationLevel = map.get("violation_level")+"";
                if (violationLevel.equals("003")){
                    treeViolationsManagementVo.setSerious(Integer.parseInt(map.get("count")+""));
                    continue;
                }
                if (violationLevel.equals("002")){
                    treeViolationsManagementVo.setLarger(Integer.parseInt(map.get("count")+""));
                    continue;
                }
                if (violationLevel.equals("001")){
                    treeViolationsManagementVo.setGenerally(Integer.parseInt(map.get("count")+""));
                    continue;
                }
            }else {
                continue;
            }
        }
        return treeViolationsManagementVo;
    }
}
